package ajjj.kiviq.controllers;

import ajjj.kiviq.beans.TestBean;
import ajjj.kiviq.beans.UserBean;
import ajjj.kiviq.entities.Category;
import ajjj.kiviq.remoteInterfaces.IRemoteCategory;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
/**
 *
 * @author orjohan
 *
 * Updated 2011-10-11 by orjohan & jeklund
 * -Added remove method for removing Categories
 *
 */
@ManagedBean
@RequestScoped
public class TestController {

    @ManagedProperty(value = "#{testBean}")
    private TestBean testBean;
    @EJB
    private IRemoteCategory cf;
    @ManagedProperty(value = "#{UserBean}")
    private UserBean ub;
    
    /** Creates a new instance of TestController */
    public TestController() {
    }
    
    /**
     * Starts a test
     * 
     * @param c The Category that the user wants
     * to test
     * @return A redirect string that redirects
     * to the test
     */
    public String takeTest(Category c) {
        testBean.setCategory(c);
        return "test?faces-redirect=true";
    }
    
    /**
     * Removes a single Category from the
     * database (TODO: Why is this here?)
     * 
     * @param c The Category to remove
     * @return A string pointing back to the
     * categories page
     */
    public String remove(Category c){
	String user = ub.currentUser();
        cf.removeCategory(c, user);
        return "toCat";
    }

    /**
     * Get the TestBean associated to this controller
     * @return The TestBean
     */
    public TestBean getTestBean() {
        return testBean;
    }

    /**
     * Set the TestBean associated to this controller
     * @param testBean The TestBean
     */
    public void setTestBean(TestBean testBean) {
        this.testBean = testBean;
    }

    /**
     * Get the UserBean associated to this controller
     * @return The UserBean
     */
    public UserBean getUb() {
        return ub;
    }

    /**
     * Set the Userbean associated to this controller
     * @param ub The UserBean
     */
    public void setUb(UserBean ub) {
        this.ub = ub;
    }
    
}
